
package Loader;

import java.io.File;
import java.util.LinkedList;
import java.util.Scanner;

public class LoaderIrys implements LoaderInterface {

    public LinkedList<Pair> load(String fileName) {

        LinkedList<Pair> data = new LinkedList<Pair>();
        File fFile = new File(fileName);
        Scanner scanner = null;

        try {

            scanner = new Scanner(fFile);

            while ( scanner.hasNextLine() ){

                Scanner scannerL = new Scanner(scanner.nextLine());
                scannerL.useDelimiter(",");

                 if ( scannerL.hasNext() ) {

                    float[] features = new float[4];

                    for(int i=0;i<4;++i)
                        features[i] = Float.parseFloat(scannerL.next());

                    String name = scannerL.next();
                    int noClass = 0;

                    if(name.equals("Iris-setosa"))
                        noClass = 1;
                    else if(name.equals("Iris-versicolor"))
                        noClass = 2;
                    else if(name.equals("Iris-virginica"))
                        noClass = 3;

                    data.add(new Pair(noClass, features));

                 }

            }

        } catch(Exception e) {

            System.out.println(e);
            return null;

        }

        scanner.close();
        return data;
        
    }

}
